<style lang="less">
  @import 'UpdateInfo.less';
</style>
<template>
  <Form :model="formItem" :label-width="80">
    <input type="hidden" v-model="formItem.id">
    <FormItem label="名称">
      <Input v-model="formItem.name" placeholder="请输入名称">
        <Icon type="ios-person-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem label="密码">
      <Input v-model="formItem.password" placeholder="如果不需要修改密码请留空">
        <Icon type="ios-lock-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem label="社会代码">
      <Input v-model="formItem.code" placeholder="请输入社会代码">
        <Icon type="ios-barcode-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem label="邮箱">
      <Input v-model="formItem.email" placeholder="请输入邮箱">
        <Icon type="ios-mail-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem label="电话">
      <Input v-model="formItem.phone" placeholder="请输入电话">
        <Icon type="ios-call-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem label="头像">
      <Upload
        ref="upload"
        :show-upload-list="false"
        :default-file-list="defaultList"
        :on-success="handleSuccess"
        :format="['jpg','jpeg','png']"
        :max-size="2048"
        :on-format-error="handleFormatError"
        :on-exceeded-size="handleMaxSize"
        :before-upload="handleBeforeUpload"
        multiple
        type="drag"
        action="http://71bbs.people.com.cn/postImageUpload.do"
        style="display: inline-block;width:58px;">
        <div style="width: 58px;height:58px;line-height: 58px;">
          <Icon type="ios-camera" size="20"></Icon>
        </div>
      </Upload>
    </FormItem>
    <Button type="primary" size="large" class="on-btn" @click="btnSaveClick">确认修改</Button>
  </Form>
</template>

<script>
  import {getOrganization, updateOrganization, getCurrentOrganization} from '@/api/organization'

  export default {
    name: 'UpdateInfo',
    data() {
      return {
        formItem: {
          id: '',
          name: '',
          password: '',
          code: '',
          email: '',
          phone: '',
          avatar: '',
          sid: ''
        }
      }
    },
    mounted() {
      this.queryList();
    },
    methods: {
      queryList: function () {
        getCurrentOrganization().then(res => {
          const {id, name, code, email, phone, avatar,sid} = res.data;
          this.formItem = {
            id, name, code, email, phone, avatar,sid,
            password:''
          };
        });
      },
      handleBeforeUpload() {

      },

      btnSaveClick: function () {
        updateOrganization(this.formItem.id, this.formItem).then(res => {
          if (res.data && res.data.affectedRows > 0) {
            this.$Message.success('保存成功!');
            this.queryList();
          } else {
            this.$Message.error(res.error);
          }
        });
      },
    }
  }

</script>
